<template>
  <div class="chart">
    <div ref="bar" style="width: 80%; height: 300px; margin: auto"></div>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {};
  },
  computed: {
    rosedata() {
      return this.$store.state.clickeddata;
    },
    newdata() {
      return this.$store.state.clickeddata;
    },
  },
  components: {},
  mounted() {
    this.dataEcharts();
  },
  watch: {
    newdata() {
      this.dataEcharts();
    },
  },
  methods: {
    dataEcharts: function (demo) {
      // 基于准备好的dom，初始化echarts实例
      // console.log(this.rosedata);
      var myChart = this.$echarts.init(this.$refs.bar);

      // 绘制图表
      myChart.setOption({
        title: {
          text: "恋与制作人人气统计：",
        },
        tooltip: {},
        xAxis: {
          data: ["10-14", "14-18", "18-25", "25-35", "35+"],
        },
        yAxis: {},
        series: [
          {
            name: "受众人数",
            type: "line",
            data: [
              this.rosedata.A,
              this.rosedata.B,
              this.rosedata.C,
              this.rosedata.D,
              this.rosedata.E,
            ],
          },
        ],
      });
      window.addEventListener("resize", () => {
        myChart.resize();
      });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>